from rest_framework import viewsets
from rest_framework.permissions import IsAuthenticated

from interfaces.models import Interface
from interfaces.serializers import InterfaceSerializer


class InterfaceViewSet(viewsets.ModelViewSet):
    queryset = Interface.objects.all().filter(is_deleted=False)
    serializer_class = InterfaceSerializer
    permission_classes = [IsAuthenticated]
    filterset_fields = ['type', 'project']  # noqa
    ordering = ['-create_time']  # 默认排序方式

    def perform_destroy(self, instance):
        instance.is_deleted = True
        instance.save()
